package com.groupbuying.currency.consumer.service.impl;


import com.groupbuying.currency.consumer.connector.FinancialFeign;
import com.groupbuying.currency.consumer.constants.ReturnCodeEnum;
import com.groupbuying.currency.consumer.service.OperCurrencyService;
import com.groupbuying.currency.consumer.utils.HttpClientUtils;
import com.groupbuying.currency.consumer.utils.JSONUtils;
import com.groupbuying.currency.consumer.utils.RedisUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * @auter miaozhenfei
 * @date 2019/9/3 11:48
 */
@Service
public class OperCurrencyServiceImpl implements OperCurrencyService {
    private static Logger log = LoggerFactory.getLogger(OperCurrencyServiceImpl.class);
    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    private HttpClientUtils httpClientUtils;
    @Autowired
    private FinancialFeign financialFeign;


    //    发送积分直接核减成功的异步mq调用
    @Override
    public boolean sendMqForSubOrderCurrency(Map mapParams) {

        Object temp = mapParams.get("prePayNo");
        String prePayNo = temp != null ? temp.toString() : null;

        temp = mapParams.get("currencyCode");
        String currencyCode = temp != null ? temp.toString() : null; // 位置
        temp = mapParams.get("message");
        String message = temp != null ? temp.toString() : null;
        temp = mapParams.get("orderNum");
        String orderNum = temp != null ? temp.toString() : null;
        log.error("接收到生产者产生的支付成功数据" + JSONUtils.parseJSON(mapParams));
        Map returnMap = new HashMap();
        String result = null;
        if (null == prePayNo || null == currencyCode || null == message || null == orderNum) {
            returnMap.put("return_code", ReturnCodeEnum.PARAMNULL.getKey());
            returnMap.put("message", ReturnCodeEnum.PARAMNULL.getValue());
//            return JsonUtils.objectToJson(returnMap);
            log.error(" 发送积分核减成功的异步mq" + JSONUtils.parseJSON(returnMap));

            return false;
        }
        log.error("调用优店的financial模块的feign接口" + JSONUtils.parseJSON(mapParams));
        financialFeign.integralpay(mapParams);
        return true;

    }
}
